package com.yl.util;

import com.yl.entity.cdc.MysqlCdcEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wlf
 * @since 2022/8/29
 */
public class ClassUtil {

    /**
     * 把 MysqlCdcEntity 中存储的对象转换成原来的类型
     */
    public static <T> T cast(MysqlCdcEntity cdcEntity, Class<T> tClass) {
        if (null != cdcEntity) {
            return tClass.cast(cdcEntity.getEntity());
        }
        return null;
    }

    /**
     * 把 MysqlCdcEntity 中存储的对象转换成原来的类型
     */
    public static <T> List<T> cast(List<MysqlCdcEntity> cdcEntityList, Class<T> tClass) {
        List<T> res = new ArrayList<>();
        if (null != cdcEntityList) {
            for (MysqlCdcEntity cdcEntity : cdcEntityList) {
                res.add(tClass.cast(cdcEntity.getEntity()));
            }
        }
        return res;
    }

}
